package com.haiyu.manager.controller.platform;

import com.haiyu.manager.response.PageDataResult;
import com.haiyu.manager.service.TalkService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("talk")//指定路由
public class TalkController {
    @Autowired
    TalkService talkService;
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     *
     * 功能描述: 分页查询board列表
     *
     *
     */
    @RequestMapping(value = "/getTalkList", method = RequestMethod.POST)
    @ResponseBody
    public PageDataResult getTalkList(@RequestParam("pageNum") Integer pageNum,
                                       @RequestParam("pageSize") Integer pageSize) {
        System.out.println();
        PageDataResult pdr = new PageDataResult();
        try {
            if(null == pageNum) {
                pageNum = 1;
            }
            if(null == pageSize) {
                pageSize = 10;
            }
            // 获取列表
            pdr = talkService.getTalkList( pageNum ,pageSize);
            logger.info("Talk列表查询=pdr:" + pdr);

        } catch (Exception e) {
            e.printStackTrace();
            logger.error("Talk列表查询异常！", e);
        }
        return pdr;
    }


    /**
     *
     * 功能描述: 删除/恢复 board
     *
     *
     */
    @RequestMapping(value = "/updateTalkStatus", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> updateTalkStatus(@RequestParam("talkId") Integer talkId, @RequestParam("houtaiStatus") Integer houtaiStatus) {
        logger.info("删除/恢复留言！talkId:" + talkId+" houtaiStatus:"+houtaiStatus);
        Map<String, Object> data = new HashMap<>();
        if(houtaiStatus == 1){
            //删除liuyan
            data = talkService.delTalk(talkId,houtaiStatus);
        }else{
            //恢复liuyan
           // data = boardService.recoverBoard(boardId,boardStatus);
        }
        return data;
    }

}
